﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace DataConvertLib
{
	/// <summary>
	/// Int类型数据转换类
	/// </summary>
	// Token: 0x0200000B RID: 11
	[Description("Int类型数据转换类")]
	public class IntLib
	{
		/// <summary>
		/// 字节数组中截取转成32位整型
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="start">开始索引</param>
		/// <param name="dataFormat">数据格式</param>
		/// <returns>返回int类型</returns>
		// Token: 0x06000054 RID: 84 RVA: 0x00003D00 File Offset: 0x00001F00
		[Description("字节数组中截取转成32位整型")]
		public static int GetIntFromByteArray(byte[] value, int start = 0, DataFormat dataFormat = DataFormat.ABCD)
		{
			byte[] value2 = ByteArrayLib.Get4BytesFromByteArray(value, start, dataFormat);
			return BitConverter.ToInt32(value2, 0);
		}

		/// <summary>
		/// 将字节数组中截取转成32位整型数组
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="dataFormat">数据格式</param>
		/// <returns>返回int数组</returns>
		// Token: 0x06000055 RID: 85 RVA: 0x00003D24 File Offset: 0x00001F24
		[Description("将字节数组中截取转成32位整型数组")]
		public static int[] GetIntArrayFromByteArray(byte[] value, DataFormat dataFormat = DataFormat.ABCD)
		{
			bool flag = value == null;
			if (flag)
			{
				throw new ArgumentNullException("检查数组长度是否为空");
			}
			bool flag2 = value.Length % 4 != 0;
			if (flag2)
			{
				throw new ArgumentNullException("检查数组长度是否为4的倍数");
			}
			int[] array = new int[value.Length / 4];
			for (int i = 0; i < value.Length / 4; i++)
			{
				array[i] = IntLib.GetIntFromByteArray(value, 4 * i, dataFormat);
			}
			return array;
		}

		/// <summary>
		/// 将字符串转转成32位整型数组
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="spilt">分隔符</param>
		/// <returns>返回int数组</returns>
		// Token: 0x06000056 RID: 86 RVA: 0x00003D94 File Offset: 0x00001F94
		[Description("将字符串转转成32位整型数组")]
		public static int[] GetIntArrayFromString(string value, string spilt = " ")
		{
			value = value.Trim();
			List<int> list = new List<int>();
			int[] result;
			try
			{
				bool flag = value.Contains(spilt);
				if (flag)
				{
					string[] array = value.Split(new string[]
					{
						spilt
					}, StringSplitOptions.RemoveEmptyEntries);
					foreach (string text in array)
					{
						list.Add(Convert.ToInt32(text.Trim()));
					}
				}
				else
				{
					list.Add(Convert.ToInt32(value.Trim()));
				}
				result = list.ToArray();
			}
			catch (Exception ex)
			{
				throw new ArgumentNullException("数据转换失败：" + ex.Message);
			}
			return result;
		}

		/// <summary>
		/// 通过布尔长度取整数
		/// </summary>
		/// <param name="boolLength">布尔长度</param>
		/// <returns>整数</returns>
		// Token: 0x06000057 RID: 87 RVA: 0x00003E4C File Offset: 0x0000204C
		[Description("通过布尔长度取整数")]
		public static int GetByteLengthFromBoolLength(int boolLength)
		{
			return (boolLength % 8 == 0) ? (boolLength / 8) : (boolLength / 8 + 1);
		}
	}
}
